package edu.langnan.xiaoli.controller.business;

import edu.langnan.xiaoli.base.AjaxResult;
import edu.langnan.xiaoli.base.controller.BaseController;
import edu.langnan.xiaoli.config.security.TokenService;
import edu.langnan.xiaoli.core.dto.NucleicBaseInfoDTO;
import edu.langnan.xiaoli.core.dto.NucleicParamDTO;
import edu.langnan.xiaoli.core.dto.NucleicStudentInfoDTO;
import edu.langnan.xiaoli.service.NucleicAcidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author cql
 */
@RestController
@RequestMapping("nucleic")
public class NucleicAcidController extends BaseController {

    @Autowired
    private NucleicAcidService nucleicAcidService;

    @Autowired
    private TokenService tokenService;

    @GetMapping("list")
    public AjaxResult studentOfNucleicList(HttpServletRequest request) {

        Integer stuId = tokenService.getLoginUser(request).getId();
        List<NucleicStudentInfoDTO> result = nucleicAcidService.studentOfNucleicList(stuId);

        return AjaxResult.success(result);
    }

    @GetMapping("{nid}")
    public AjaxResult nucleicById(@PathVariable("nid") Integer nid, HttpServletRequest request) {
        Integer stuId = tokenService.getLoginUser(request).getId();
        NucleicStudentInfoDTO result = nucleicAcidService.nucleicById(stuId, nid);
        return AjaxResult.success(result);
    }

    @PostMapping()
    public AjaxResult uploadNucleic(@RequestBody NucleicParamDTO param, HttpServletRequest request) {
        Integer stuId = tokenService.getLoginUser(request).getId();
        param.setStuId(stuId);
        nucleicAcidService.uploadNucleic(param);
        return AjaxResult.success();
    }

}
